home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
yerk
/
mps231ss.hqx
/
Mops source
/
Toolbox classes
/
Ctl
< prev
next >
Wrap
Text File
|
1993-01-23
|
6KB
|
213 lines
\ Control support. Mops version.
\ Nov 90 Added Bob Loewenstein's improvements
\ Nov 91 Controls now owned by views, not windows
\ May 92 "New-style" controls
\ With Mops 2.2 we are introducing a "new style" of controls.
\ In line with the view philosophy, it is more logical if when NEW: or
\ DRAW: is sent to a view, it sends NEW: or DRAW: to all its controls
\ automatically. This means that NEW: for all types of control should
\ have the same stack effects. Therefore we are now introducing a
\ recommended way of handling controls along the lines of menus etc.
\ -- i.e. with an INIT: method which sets the control up, then with NEW:
\ taking only one parameter, the owning view, and firing up the control
\ according to the values already set up with INIT:.
\ So as not to break existing code, we are leaving the Control class
\ as is, and introducing subclasses which have this new behavior.
\ These are Button, RadioButton and CheckBox, which are subclasses of
\ the generic TitledCtl. I think these classes also give a better
\ factorization than we had before, where all controls apart from
\ scroll bars were generic and had their types set by the procID passed
\ to INIT:. It's not normal for a control type to be changed on the fly
\ -- separate classes are more natural, I think.
\ Unfortunately this has necessitated us changing vscroll and hscroll
\ to the "new style", and this may require existing code to be changed.
\ Sorryyy!!!!!
0 value ThisCtl
0 value ThisView
: GET-CTL-OBJ \ ( ctlhndl -- objptr )
\ Gets ptr to ctl obj from ctl record
0 swap call GetCRefCon dup -> thisCtl
dup getView: [] -> thisView ;
: SET-CTL-OBJ \ ( objptr ctlhndl -- )
\ Sets ptr to ctl obj in ctl record
swap dup -> thisCtl call SetCRefCon ;
: TWIDTH \ ( addr len -- width )
\ Returns width of string in current font
str255 >r word0 r> call StringWidth word0 ;
0 constant BUTTONID \ control types
1 constant CHECKID
2 constant RADIOID
16 constant VSID
\ ======================
\ Control is the basic control class for simple controls - buttons, etc.
:class CONTROL super{ object }
int PROCID
int RESID
handle CTLHNDL
dicAddr ACTION
int MyVALUE
ptr ^MyVIEW
:m PUTRESID: \ ( resID -- )
put: resID ;m
:m EXEC: \ ( part# -- ) performs action for control
if get: action execute then ;m
:m UPDATE: \ Cause the control to be drawn
ptr: CtlHndl 8 + call InvalRect ;m
:m DRAW: ;m \ This is for any custom drawing in subclasses.
:m HIDE: get: Ctlhndl call HideControl ;m
:m SHOW: get: Ctlhndl call ShowControl ;m
:m MOVETO: \ ( x y -- ) Moves control to x,y location
pack get: ctlhndl swap call MoveControl ;m
:m MOVE: moveTo: self ;m
:m SIZE: \ ( w h -- ) Sets width, height of control's rect
pack get: ctlhndl swap call SizeControl ;m
:m SETSIZE: \ ( w h -- ) Synonym for SIZE:.
size: self ;m
:m INIT: ( procid -- ) put: procid ;m
:m SETVIEW: \ ( ^view -- ) Use this to initialize the owning view.
put: ^myView ;m
:m GETVIEW: get: ^myView ;m
:m ACTIONS: \ ( xt -- ) Sets the action for this control
put: action ;m
:m PUT: { theVal -- } \ Sets the ctl value.
get: ^myView enabled?: **
if theVal get: ctlHndl swap makeint call SetCtlValue then
theVal put: myValue ;m
:m GET: \ ( -- val ) Some ctls may need original value,
\ e.g. scroll bar
get: ^myView enabled?: **
if word0 get: ctlHndl call getCtlValue word0
else get: myValue
then ;m
private
:m (SETUP): { theView -- }
^base get: ctlHndl set-ctl-obj initFont
theView put: ^myView get: myValue put: self ;m
public
\ NEW: (x y addr len theView) fires up the control. x, y is the top left coordinate relative to the bounding rectangle of the containing view.
:m NEW: { x y addr len theView \ titleWidth -- }
getRect: theView 2drop \ ( left top )
++> y ++> x \ Make x,y rel to grafport as reqd
get: procID 8 and \ window font if true
nif 0 tFont 12 tSize ( Chicago 12 ) then
addr len tWidth -> titleWidth
x y x titleWidth + 17 + y 17 + put: tempRect
0 window: theView addr: tempRect addr len str255
w 256 word0 word0 w 1 int: procid ^base
call NewControl put: ctlHndl
theView (setup): self ;m
:m GETNEW: { theView -- }
\ Creates a new control on the heap, using a resource.
0 int: resID window: theView
call GetNewControl put: ctlHndl
theView (setup): self ;m
:m HANDLE: \ ( -- ctlhndl )
get: ctlHndl ;m
:m HILITE: \ ( hiliteState -- ) Hilite a part or entire control
get: ctlHndl swap makeInt
call HiliteControl ;m
:m DISABLE: -1 hilite: self ;m
:m ENABLE: 0 hilite: self ;m
:m GETRECT: \ ( -- l t r b ) Stacks bounds rectangle
ptr: ctlHndl 8 + get: rect ;m
:m SETTITLE: \ ( addr len -- )
str255 get: ctlHndl swap call setCTitle ;m
:m GETTITLE: \ ( -- addr len )
get: ctlhndl pad call getCTitle pad count ;m
:m CLOSE: get: ctlHndl call DisposControl ;m
:m RELEASE: close: self ;m \ Standard Mops "shutdown" method name
:m CLASSINIT: \ Sets default control to a standard button
buttonID init: self ['] null actions: self ;m
;class
:class TITLEDCTL super{ control }
int TOP
int LEFT
int TitleLen
32 bytes TITLE
\ INIT: sets up the control with a title. x, y is the top left coordinate
\ relative to the bounding rectangle of the containing view. (addr len)
\ gives the title.
:m INIT: \ ( x y addr len -- )
32 min dup put: titleLen addr: title swap cmove
put: top put: left ;m
:m NEW: { theView -- }
get: left get: top
addr: title get: titleLen theView new: super ;m
;class
:class BUTTON super{ titledCtl }
;class
:class CHECKBOX super{ titledCtl }
:m CLASSINIT: classinit: super checkID put: procID ;m
;class
:class RADIOBUTTON super{ titledCtl }
:m CLASSINIT: classinit: super radioID put: procID ;m
;class
variable THECTL
\ control part codes
10 constant INBUTTON \ simple button
11 constant INCHECKBOX \ check box or radio button
129 constant INTHUMB
20 constant INUPBUTTON \ up arrow in scroll bar
21 constant INDOWNBUTTON \ down arrow
22 constant INPAGEUP
23 constant INPAGEDOWN
8 constant USEWFONT \ Add to ID if title in application font